package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBCDemo14 {
    public static void main(String[] args) {
        try(Connection connection=DBUtil.getconnection()){
            connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            connection.setAutoCommit(false);
            String sql="INSERT INTO userinfo (username,password,nickname,age) VALUES (?,?,?,?)" ;
            PreparedStatement ps=connection.prepareStatement(sql);
            ps.setString(1,"钱八");
            ps.setString(2,"123456");
            ps.setString(3,"钱八子");
            ps.setInt(4,18);
            int num=ps.executeUpdate();
            System.out.println(num>0?"添加成功！":"添加失败！");
            System.out.println(num+"行数据受影响！");
            connection.commit();
//            connection.rollback();



        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

